/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.swta;
import java.util.List;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

/**
 *
 * @author Jan
 */
public final class PackageItemsPanel extends WebMarkupContainer {

    ListView listView;
    MyItemPackage itemPackage;
    private String itemId;

    public PackageItemsPanel(String id) {
        super (id);

//        this.listView = new ListView("allItems") {
//
//            @Override
//            protected void populateItem(ListItem arg0) {
//                // nothing yet
//            }
//        };
//        add(this.listView);
    }

    private void addListView() {

//        this.remove("allItems");

        this.itemPackage = MyItemPackageManager.getInstance().getItemPackage(PackageItemsPanel.this.itemId);
        List<MyItem> itemList = itemPackage.getItemList();

        this.listView = new ListView("allItems", itemList) {

            protected void populateItem(ListItem item) {

                MyItem actItem = (MyItem) item.getModelObject();

                item.add(new InDecreasePackageItemPanel("indecrease", PackageItemsPanel.this.itemId, item.getModel(), this));
                item.add(new Label("id", actItem.getId()));
                item.add(new Label("category", actItem.getCategory()));
                item.add(new Label("name", actItem.getName()));
                item.add(new Label("weight", "" + actItem.getWeight()));
                item.add(new Label("unit", "" + actItem.getUnit()));
                item.add(new Label("count", "" + PackageItemsPanel.this.itemPackage.getItems().get(actItem.getId()).intValue()));
                item.add(new Label("price", "" + actItem.getPrice()));
            }
        };
        this.listView.setOutputMarkupId(true);

        add(this.listView);
        System.out.println("????????????" + this.listView.isVisible());
    }

    public void setItemToEdit(String itemId) {
        this.itemId = itemId;

        this.addListView();
    }

    public ListView getList() {
        return this.listView;
    }
}
